<script lang="ts" setup name="CallbackPatch">
import  useStore from '@/store'
import {  useRouter } from 'vue-router';
import { ref } from 'vue';
import Message from '@/components/message';
const {user} =useStore()
const router=useRouter()

// 获取openId
let openId=''
if(QC.Login.check()){
  QC.Login.getMe((id)=>{
    openId=id
  })
}

// 双向绑定表单
const form=ref({
     account:'',
     mobile:'',
     code:'',
     password:''
})
// 发送验证码
let time=ref(0)
const send=async ()=>{
await  user.sendQQPathMsg(form.value.mobile)
  Message.success('获取验证码成功')
  time.value=6
  let timeId=-1
   timeId=window.setInterval(()=>{
     time.value--
     if(time.value===0){
      clearInterval(timeId)
     }
   },1000)
}
// 提交
const submit=async()=>{
await  user.qqPatchLogin({
    ...form.value,
    openId
  })
  Message.success('绑定用户信息成功')
  router.push('/')
}

</script>
<template>
  <div class="xtx-form">
    <div class="xtx-form-item">
      <div class="field">
        <i class="icon iconfont icon-user"></i>
        <input class="input" type="text" placeholder="请输入用户名" v-model="form.account"/>
      </div>
      <div class="error"></div>
    </div>
    <div class="xtx-form-item">
      <div class="field">
        <i class="icon iconfont icon-phone"></i>
        <input class="input" type="text" placeholder="请输入手机号" v-model="form.mobile" />
      </div>
      <div class="error"></div>
    </div>
    <div class="xtx-form-item">
      <div class="field">
        <i class="icon iconfont icon-code"></i>
        <input class="input" type="text" placeholder="请输入验证码" v-model="form.code"/>
        <span class="code" @click="send">{{time===0?'发送验证码':`${time}s后发送`}}</span>
      </div>
      <div class="error"></div>
    </div>
    <div class="xtx-form-item">
      <div class="field">
        <i class="icon iconfont icon-lock"></i>
        <input class="input" type="password" placeholder="请输入密码" v-model="form.password"/>
      </div>
      <div class="error"></div>
    </div>
    <!-- <div class="xtx-form-item">
      <div class="field">
        <i class="icon iconfont icon-lock"></i>
        <input class="input" type="password" placeholder="请确认密码" />
      </div>
      <div class="error"></div>
    </div> -->
    <a href="javascript:;" class="submit" @click="submit">立即提交</a>
  </div>
</template>

<style scoped lang="less">
.code {
  position: absolute;
  right: 0;
  top: 0;
  line-height: 50px;
  width: 80px;
  color: #999;
  &:hover {
    cursor: pointer;
  }
}
</style>
